package com.gw.detail.controllor.param;

import com.gw.detail.domain.param.CommonCode;
import com.gw.detail.service.param.ICommonCodeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报警模式Controller
 *
 * @author WangBin
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/detail/common")
public class CommonCodeController extends BaseController {
    @Autowired
    private ICommonCodeService commonCodeService;

    /**
     * 查询报警模式列表
     */
    @PreAuthorize("@ss.hasPermi('detail:common:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonCode commonCode) {
        startPage();
        List<CommonCode> list = commonCodeService.selectCommonCodeList(commonCode);
        return getDataTable(list);
    }

    /**
     * 导出报警模式列表
     */
    @PreAuthorize("@ss.hasPermi('detail:common:export')")
    @Log(title = "报警模式", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CommonCode commonCode) {
        List<CommonCode> list = commonCodeService.selectCommonCodeList(commonCode);
        ExcelUtil<CommonCode> util = new ExcelUtil<CommonCode>(CommonCode.class);
        return util.exportExcel(list, "报警模式数据");
    }

    /**
     * 获取报警模式详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:common:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(commonCodeService.selectCommonCodeById(id));
    }

    /**
     * 新增报警模式
     */
    @PreAuthorize("@ss.hasPermi('detail:common:add')")
    @Log(title = "报警模式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonCode commonCode) {
        return toAjax(commonCodeService.insertCommonCode(commonCode));
    }

    /**
     * 修改报警模式
     */
    @PreAuthorize("@ss.hasPermi('detail:common:edit')")
    @Log(title = "报警模式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonCode commonCode) {
        return toAjax(commonCodeService.updateCommonCode(commonCode));
    }

    /**
     * 删除报警模式
     */
    @PreAuthorize("@ss.hasPermi('detail:common:remove')")
    @Log(title = "报警模式", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(commonCodeService.deleteCommonCodeByIds(ids));
    }
}
